import React, { Component } from 'react';
import { Row, Col, message,Input, Icon,Form, Cascader, DatePicker, Button, Tooltip, Popconfirm } from 'antd';

import{BasicFormItem} from './BasicFormItem';
import moment from 'moment';
import {DATEFORMAT} from '../common/common';




class BasicForm extends Component{
    constructor(props) {
        super(props);
        this.state = {};
    }

    render(){
        let self = this;
        let schemaJson = [];
        let intiState = [];
        let dataJson = [];
        let isNew =false;
        let propform = this.props.form;
        let editing = self.props.editing;
        const { getFieldDecorator} = this.props.form;
        let ruleJson = {validateDict: null, eventDict: null};
        let objectEditDto ={id:'Emp0000000005',type:'E'}
        let stepKeycode ='HRMB0011';
        let  listRows = 3;
        let infoSetName = self.props.schema.name;
        schemaJson = self.props.schema.fieldList;
        
        if (self.props.rootComponent && self.props.currentOperationStepKey) {
            console.log('self.props.rootComponent.state');
            console.log(self.props.rootComponent.state);
           if(self.props.rootComponent.state!==null)
           {
              
               //lynn 表单字段赋值
                self.props.rootComponent.state[self.props.currentOperationStepKey] = self;
                console.log('self.props.currentOperationStepKey');
                console.log(self.props.rootComponent);
           }
            
        }

        // schemaJson.orderBy(function (m) {
        //     return m.sortIndex;
        // });

        ruleJson = {eventDict:{},validateDict:{}}
        
        intiState = {
            "vid": '',
            "Begin":  new Date(),
            "End":  '9999-12-31'
        };
        return(<div>
                <Form className="c-dyn-form-ver">
                <Row className="infoSet-title">
                        <Col span={8}>
                            <div className="title">{infoSetName}</div>
                        </Col>
                        <Col span={16} className="c-tar">
                            {
                                <div>
                                    {
                                        getFieldDecorator("begin", {initialValue: moment(intiState["Begin"])})(
                                            <DatePicker onChange={this.onStartChange}
                                                        format={DATEFORMAT}
                                                        disabledDate={this.disabledStartDate}/>)
                                    }
                                    {
                                        getFieldDecorator("end", {initialValue: moment(intiState["End"])})(
                                            <DatePicker onChange={this.onEndChange} format={DATEFORMAT}
                                                        disabledDate={this.disabledEndDate}/>)
                                    }
                                </div>
                            }
                        </Col>
                    </Row>
                    <Row  className="section">{ schemaJson.map(function (schema, index) {
                                    return (<BasicFormItem key={index}
                                                            schema={schema}
                                                            intistate={intiState}
                                                            infosetcode={stepKeycode}
                                                            propform={propform}
                                                            rootComponent={self.props.rootComponent}
                                                            rule={ruleJson}
                                                            editing={editing}
                                                            objectEditDto={objectEditDto}
                                                            Rows={listRows}
                                                            rootForm={self}
                                                            isNew={isNew}/>
                                        )
                                    }
                                )
                            }
                    </Row>
                
                </Form>
                     
            </div>)
    }
}


BasicForm = Form.create()(BasicForm);
export {
    BasicForm as BasicForm
}